<?php

class Model_ZendDb_Paginator_SearchUser extends Zend_Paginator_Adapter_DbSelect
{
	/**
     * @var Model_ZendDb_DbTable_UserProfile
     */
    private $_profile;
    
    public function __construct(Zend_Db_Select $select)
    {
    	parent::__construct($select);
    	
        $this->_profile = new Model_ZendDb_DbTable_UserProfile();
    }
    
	/**
	 * @param $offset
	 * @param $itemCountPerPage
	 * @return array of Model_Entity_User
	 */
	public function getItems($offset, $itemCountPerPage) {
		$resultSet = parent::getItems($offset, $itemCountPerPage);
		
	    $entries = array();
        
        //$resultSet = $this->_db->fetchAll($select);
        foreach ($resultSet as $row) {
            $user = new Model_Entity_User($row);
            
            $profile = new Model_Entity_UserProfile(
               $this->_profile->find($row['profile_oid'])->current()->toArray()
            );
            
            $user->setUserProfile($profile);
            
            $entries[] = $user; 
        }
        
        return $entries;
	}
	
    /**
     * Returns the total number of rows in the result set.
     *
     * @return integer
     */
    public function count()
    {
        return parent::count();
    }
}
